/**
 * Copyright ©2012-2018 HopeHaiyang Corporation, All Rights Reserved
 * http://www.wuhanhope.com
 */
package hope.platform.data.web;

import hope.platform.data.domain.DataManagement;
import hope.platform.data.server.data.header.DataManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * class info
 *
 * @author hujia
 *         Create at 2018/7/10 14:40
 */
@RestController
@RequestMapping("/dataManagement")
public class DataManageController {

    @Autowired
    private DataManagementService service;

    @RequestMapping(method = RequestMethod.POST)
    public DataManagement AddDataManagement(@RequestBody DataManagement dataManagement) throws Exception {
        if (service.getDataManagementByDataName(dataManagement.getDataName()) != null) {
            throw new Exception("dataName is repeated.");
        }
        return service.addDataManagement(dataManagement);
    }

    @RequestMapping(value = "/dataName/{dataName}", method = RequestMethod.GET)
    public DataManagement getDataManagementByDataName(@PathVariable String dataName) throws Exception {
        return service.getDataManagementByDataName(dataName);
    }

    @RequestMapping(value = "/dataKind/{dataKind}", method = RequestMethod.GET)
    public List<DataManagement> getDataManagementByDataKind(@PathVariable String dataKind) throws Exception {
        return service.getDataManagementByDataKind(dataKind);
    }

    @RequestMapping(value = "/all",method = RequestMethod.GET)
    public List<DataManagement> getAll(){
        return service.getAll();
    }
}
